<?php
/*
Plugin Name: 节假日
Plugin URI: 
Description: 可以用来设置全国每天的节假日和周末上班日。
Version: 1.0
*/

add_filter('wpjam_holiday', 'wpjam_is_holiday_advanced', 10, 2);
function wpjam_is_holiday_advanced($is_holiday, $date=''){

	$date		= ($date)?$date:date('Y-m-d', current_time('timestamp'));
	$year		= date('Y', strtotime($date));

	if($wpjam_holiday	= wpjam_get_holidays()){
		// if($is_holiday){
			if(isset($wpjam_holiday['workdays_'.$year]) && isset($wpjam_holiday['workdays_'.$year][$date])){
				return 0;
			}
		// }else{
			if(isset($wpjam_holiday['holidays_'.$year]) && isset($wpjam_holiday['holidays_'.$year][$date])){
				return 2;	// 法定节假日
			}
		// }
	}

	return $is_holiday;
}

function wpjam_get_holidays(){
	if($wpjam_holiday = wpjam_get_option('wpjam-holiday')){
		foreach ($wpjam_holiday as $key => $holidays) {
			unset($wpjam_holiday[$key]);
			if(!$holidays) continue;

			foreach ($holidays as $holiday) {
				if(!$holiday) continue;

				$holiday = explode('|', $holiday.'|');
				$wpjam_holiday[$key][$holiday[0]] = $holiday[1];		
			}
		}
	}

	return $wpjam_holiday;
}

